package com.example.clxy.controller;

import com.example.clxy.entity.Experiment;
import com.example.clxy.entity.dto.ExperimentDto;
import com.example.clxy.interceptor.AppToken;
import com.example.clxy.result.PageResult;
import com.example.clxy.result.WebRestResult;
import com.example.clxy.result.business.ExperimentResult;
import com.example.clxy.result.business.PageResult.ExperimentPageResult;
import com.example.clxy.service.ExperimentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

/**
 * @Author liuhaoqi
 * @Date 2020/8/4 10:03
 * @Version 1.0
 */
@AppToken
@RestController
@RequestMapping("ExperimentController")
public class ExperimentController {

    @Autowired
    ExperimentService experimentService;


    /**
     * 新增子实验
     *
     * @param experimentDto
     * @return
     */
    @CrossOrigin
    @PostMapping("addExperiment")
    public WebRestResult addExperiment(@RequestBody ExperimentDto experimentDto) {
        WebRestResult result = experimentService.addExperiment(experimentDto);
        return result;
    }

    /**
     * 更新子实验
     *
     * @param experimentDto
     * @return
     */
    @CrossOrigin
    @PostMapping("updateExperiment")
    public WebRestResult updateExperiment(@RequestBody ExperimentDto experimentDto) {
        WebRestResult result = experimentService.updateExperiment(experimentDto);
        return result;
    }

    /**
     * 删除子实验
     *
     * @param experimentid
     * @return
     */
    @CrossOrigin
    @PostMapping("deleteExperiment")
    public WebRestResult deleteExperiment(String experimentid) {
        WebRestResult result = experimentService.deleteExperiment(experimentid);
        return result;
    }

    /**
     * 获取子实验列表
     *
     * @param experimentname
     * @param experimenthour
     * @param page
     * @param pagesize
     * @return
     */
    @CrossOrigin
    @GetMapping("getExperimentList")
    public PageResult<ExperimentPageResult> getExperimentList(String experimentname, String experimenthour
            , int page, int pagesize,String status) {
        PageResult<ExperimentPageResult> result =
                experimentService.getExperimentList(experimentname, experimenthour, page, pagesize,status);
        return result;
    }


    @CrossOrigin
    @GetMapping("getExperimentById")
    public ExperimentResult getExperimentById(String experimentid) {
        ExperimentResult result = experimentService.getExperimentById(experimentid);
        return result;
    }

    @CrossOrigin
    @PostMapping("uploadExperimentBook")
    public WebRestResult uploadExperimentBook(MultipartFile file) {
        WebRestResult result = experimentService.uploadExperimentBook(file);
        return result;
    }
}
